package com.ytjj.qmyx.users.controller;

import com.ytjj.common.api.CommonResult;
import com.ytjj.common.controller.BaseController;
import com.ytjj.common.model.UsersResponse;
import com.ytjj.qmyx.users.model.AddUserScoreRequest;
import com.ytjj.qmyx.users.service.UserScoreService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 添加用户积分控制器
 *
 *
 *  *
 **/
@RestController
@RequestMapping("/userScore")
public class UserScoreController extends BaseController {

    @Resource
    private UserScoreService userScoreService;

    @PostMapping("/add")
    public String addScore(@Validated @RequestBody AddUserScoreRequest addUserScoreRequest) {
        return userScoreService.addScore(addUserScoreRequest);
    }

    @GetMapping("/getScoreTask")
    public CommonResult getScoreTask () {
        UsersResponse currentUser = this.getCurrentUser();
        if(currentUser == null || currentUser.getId() == null) {
            return CommonResult.success();
        }
        return CommonResult.success(userScoreService.getScoreTask(currentUser.getId()));
    }
}
